package com.daiyang.lease.web.admin.controller.apartment;

import com.daiyang.lease.common.result.Result;
import com.daiyang.lease.model.entity.LeaseTerm;
import com.daiyang.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name ="房间租期管理")
@RestController

@RequestMapping("/admin/term")
public class LeaseTermController {
    @Autowired
    private LeaseTermService leaseTermService;

    @Operation(summary = "查询全部租期列表")
    @GetMapping("/list")
    public Result<List<LeaseTerm>> ListLeaseTerm() {
        List<LeaseTerm> list = leaseTermService.list();
        return Result.ok(list);
    }


    @Operation(summary = "保存或更新租期信息")
    @PostMapping("/saveOrUpdate")
    public Result<LeaseTerm> saveOrUpdateTerm(@RequestBody LeaseTerm leaseTerm) {
        leaseTermService.saveOrUpdate(leaseTerm);
        return Result.ok();
    }

    //根据id删除租期信息
    @Operation(summary = "根据id删除租期信息")
    @DeleteMapping ("/deleteById")
    public Result<Void> deleteLeaseTerm(@RequestParam("id") Long id) {
        leaseTermService.removeById(id);
        return Result.ok();
    }


}
